package com.zpark.controller;

import com.zpark.pojo.Ranking;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title: RestTemplateController
 * @Author Charles
 * @Package com.zpark.controller
 * @Date 2022/11/9 11:31
 */
@RestController
@RequestMapping("/rest")
public class RestTemplateController {
    @Autowired
    private RestTemplate restTemplate;

    private static final String PATH="http://localhost:10086/service";
    //获取所有数据
    @PostMapping("/all.do")
    public List<Ranking> all(){

        return restTemplate.postForObject(PATH+"/all",new ArrayList<Ranking>(),List.class);
    }
    // 根据id获取数据
    @GetMapping("/get/{id}")
    public Ranking findById(@PathVariable Integer id){
        String url=PATH+"/find_id/"+id;
        System.out.println(url);
        return restTemplate.getForObject(url,Ranking.class);
    }

}
